package com.shrct.businessprocess.budget.impl;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.shrct.businessprocess.budget.RCBudget;
import com.shrct.businessprocess.budget.RCCost4RemainItem;
import com.shrct.businessprocess.budget.RCCostBreakDown;
import com.shrct.businessprocess.budget.RCF1Budget;
import com.shrct.businessprocess.budget.RCF2Budget;
import com.shrct.businessprocess.budget.impl.RCBudgetImpl;
import com.shrct.businessprocess.budget.proxy.RCF2BudgetProxy;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectMoney;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCF2BUDGET_TYPE")
public class RCF2BudgetImpl extends RCBudgetImpl implements RCF2Budget {
  public RCF2BudgetImpl() {
    super();
  }
  
  public RCF2BudgetImpl(final RCCostBreakDown cbd) {
    super( cbd);
    
  }
  
  public RCProjectMoney getContractPrice() {
    RCCostBreakDown _cbd = this.getCbd();
    RCProject _project = _cbd.getProject();
    RCProjectMoney _zeroAmount = _project.getZeroAmount();
    return _zeroAmount;
  }
  
  public Double getContractTaxRate() {
    return Double.valueOf(0d);
  }
  
  public Double getNetTaxRate() {
    return Double.valueOf(0d);
  }
  
  public RCProjectMoney getNetPrice() {
    RCProjectMoney _xblockexpression = null;
    {
      RCCostBreakDown _cbd = this.getCbd();
      Collection<RCBudget> _budgets = _cbd.getBudgets();
      Iterable<RCF1Budget> _filter = Iterables.<RCF1Budget>filter(_budgets, RCF1Budget.class);
      final Function1<RCF1Budget,Boolean> _function = new Function1<RCF1Budget,Boolean>() {
          public Boolean apply(final RCF1Budget it) {
            return Boolean.valueOf(true);
          }
        };
      RCF1Budget f1Budget = IterableExtensions.<RCF1Budget>findFirst(_filter, _function);
      RCProjectMoney _xifexpression = null;
      boolean _notEquals = (!Objects.equal(f1Budget, null));
      if (_notEquals) {
        RCProjectMoney _netPrice = f1Budget.getNetPrice();
        RCProjectMoney _multi = _netPrice.multi(Double.valueOf(0.11));
        _xifexpression = _multi;
      } else {
        RCCostBreakDown _cbd_1 = this.getCbd();
        RCProject _project = _cbd_1.getProject();
        RCProjectMoney _zeroAmount = _project.getZeroAmount();
        _xifexpression = _zeroAmount;
      }
      _xblockexpression = (_xifexpression);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getInvoiceTax() {
    RCCostBreakDown _cbd = this.getCbd();
    RCProject _project = _cbd.getProject();
    RCProjectMoney _zeroAmount = _project.getZeroAmount();
    return _zeroAmount;
  }
  
  public RCProjectMoney getExpectedCostAmount(final Double percent) {
    RCProjectMoney _xblockexpression = null;
    {
      RCCostBreakDown _cbd = this.getCbd();
      Collection<RCBudget> _budgets = _cbd.getBudgets();
      Iterable<RCF1Budget> _filter = Iterables.<RCF1Budget>filter(_budgets, RCF1Budget.class);
      final Function1<RCF1Budget,Boolean> _function = new Function1<RCF1Budget,Boolean>() {
          public Boolean apply(final RCF1Budget it) {
            return Boolean.valueOf(true);
          }
        };
      RCF1Budget f1Budget = IterableExtensions.<RCF1Budget>findFirst(_filter, _function);
      RCProjectMoney _xifexpression = null;
      boolean _notEquals = (!Objects.equal(f1Budget, null));
      if (_notEquals) {
        RCProjectMoney _expectedCostAmount = f1Budget.getExpectedCostAmount(percent);
        RCProjectMoney _multi = _expectedCostAmount.multi(Double.valueOf(0.11));
        _xifexpression = _multi;
      } else {
        RCCostBreakDown _cbd_1 = this.getCbd();
        RCProject _project = _cbd_1.getProject();
        RCProjectMoney _zeroAmount = _project.getZeroAmount();
        _xifexpression = _zeroAmount;
      }
      _xblockexpression = (_xifexpression);
    }
    return _xblockexpression;
  }
  
  public Boolean seemsFinished() {
    return Boolean.valueOf(true);
  }
  
  public Iterable<RCCost4RemainItem> getRCCost4RemainItems() {
    ArrayList<RCCost4RemainItem> _newArrayList = CollectionLiterals.<RCCost4RemainItem>newArrayList();
    return _newArrayList;
  }
  
  public String getTypeId() {
    return "RCF2Budget";
  }
  
  public static RCF2Budget create(final RCCostBreakDown cbd, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.budget.RCF2Budget rCF2Budget = new com.shrct.businessprocess.budget.impl.RCF2BudgetImpl(
    	cbd
    );
    objectFactory.create(rCF2Budget);
    return rCF2Budget;			
    
  }
  
  public static RCF2Budget createRCF2BudgetImpl(final RCCostBreakDown cbd, final IObjectFactory objectFactory, final Procedure1<RCF2Budget> init) {
    com.shrct.businessprocess.budget.RCF2Budget rCF2Budget = new com.shrct.businessprocess.budget.impl.RCF2BudgetImpl(
    	cbd
    );
    objectFactory.create(rCF2Budget);
    init.apply(rCF2Budget);
    
    return rCF2Budget;			
    
  }
  
  public RCF2BudgetProxy toProxy() {
    com.shrct.businessprocess.budget.proxy.RCF2BudgetProxy proxy = new com.shrct.businessprocess.budget.proxy.RCF2BudgetProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
